FEXP Solver  1.0.0.0
FEXPNetworkInterface.h
Go to the documentation of this file.
1 // © FEXP, FEXPEnterprise Solver, Ing. Vaclav Rek
3 //
4 // Compiler must support C++ ver.14 and later
6 #ifndef _CFEXPNETWORKINTERFACE_H_
7 #define _CFEXPNETWORKINTERFACE_H_
8 #include "FEXPCommon.h"
9 #include "FEXPDataContainer.h"
10 #include "FEXPSetting.h"
11 
17 #define LOCALHOST "127.0.0.1" // localhost IP adress
18 #define DFNETPORT 27015/*20248*/ // chosen default port
19 #define DEFAULT_SERVER_NODE_ID 0x0
20 
27 {
28 public:
29  virtual ~ICFEXPNetBase() { }
30  // pure virtual member functions
31  virtual size_t GetId() const = 0;
32  virtual void SetId(size_t id) = 0;
33 protected:
34  // [no protected members] -----------------------------
35 private:
36  // [no private members ] -----------------------------
37 };
38 
44 
47  : public ICFEXPNetBase
48 {
49 public:
50  ICFEXPNetNodeConnection(size_t node_id, std::string server_ip, size_t port);
52  // override pure virtual base function
53  virtual size_t GetId() const override { return _node_ID; }
54  virtual void SetId(size_t id) override { _node_ID = id; }
55  // member functions
56  std::string GetServerNodeIP() { return _server_IP; }
57  size_t GetCommPort () { return _port; }
58 
59  // pure virtual member functions
60  virtual void Run () = 0;
61  virtual void Close() = 0;
62 protected:
63  // additional structures for handling network communication
64  std::atomic_bool _connection_start;
65 
66  template<typename TInp, typename TFunc>
67  std::function<TFunc()> get_thread_functor(std::function<TFunc(TInp)> thread_fce, std::function<TInp()> input);
68 private:
69  size_t _node_ID;
70  std::string _server_IP;
71  size_t _port;
72 };
73 
74 // member functions
76 //--------------------------------------------------------------------------------------
77 template<typename TInp, typename TFunc>
79  std::function<TFunc(TInp)> thread_fce, std::function<TInp()> input)
80 //--------------------------------------------------------------------------------------
81 {
82  return [thread_fce, input] { return thread_fce(input()); };
83 }
84 
91 {
92 public:
96  {
117  //------------------------------------------------------------------------------------//
118  eContinue , // message info about calculation continuation
119  //------------------------------------------------------------------------------------//
120  eReceived , // message info about successfull data receiving
121  eEndDataBlock , // message info about ending of block of data sending
122  //------------------------------------------------------------------------------------//
123  eDataKey , // data key
124  eData , // data
125  //------------------------------------------------------------------------------------//
126  //------------------------------------------------------------------------------------//
127  eError , // some error
128  //------------------------------------------------------------------------------------//
129  //------------------------------------------------------------------------------------//
131  };
132  static std::string GetNetMessage(EMainNETCommunicationPoint comm);
133  static EMainNETCommunicationPoint GetNetMessage(std::string comm);
134 
138  {
151  };
152 
156  {
165  };
166 protected:
167  using t_MessageMap = std::map<EMainNETCommunicationPoint, std::string>;
169 private:
170  // [no private members ] -----------------------------
171 };
172 
176 
182 
185 {
186 public:
187  // pure virtual member functions for calculation instruction reading and setting
189  virtual void SendInstruction(size_t message, Ptr<t_ModelData> data) = 0;
190 
191  // pure virtual member functions for handling with macro model data
192  virtual Ptr<t_ModelData> GetMacroModelData() = 0;
193  virtual void AddMacroModelData(const t_ModelDataKey & key, Ptr<t_ModelDataDta> data) = 0;
194  virtual Ptr<t_ModelDataDta> GetMacroModelData(const t_ModelDataKey & key) = 0;
195 
196  static t_ModelData & GetReadModelData(Ptr<std::map<size_t, Ptr<t_ModelData>>> data, size_t key);
197 protected:
198  // [no protected members] -----------------------------
199 private:
200  // [no private members ] -----------------------------
201 };
202 
208 
211 {
212 public:
215  // data prepared flag
216  std::atomic_bool _data_for_send_prepared;
217  std::atomic_bool _data_received_prepared;
218  // current data to send to client node
220  // current data received from client node
222  // data for print out
224  // data transfer info
225  // --> model data to send to server
226  std::vector<size_t> MODEL_DATA_GET;
227  // --> model data transfer from server to client
228  std::vector<std::tuple<size_t, size_t>> MODEL_DATA_SET;
229  // macro model data
232 
233  Ptr<t_ModelDataDta> GetModelData(size_t key) { return _server_setting->GetFileContent()[key]; }
234 protected:
236 private:
237  // [no privat members ] -----------------------------
238 };
239 
241 
247 
249 template<typename TSocket>
251  : public ICFEXPNetNodeConnection
252 {
253 public:
254  ICFEXPNetServerClientNode(TSocket socket, std::string client_ip, size_t node_id, std::string server_ip, size_t port,
255  std::function<t_ENetThrdMsg (size_t, size_t )> message_gttr,
256  std::function<bool (size_t, size_t )> message_lchr,
257  std::function<void (size_t, size_t , t_ENetThrdMsg)> message_sttr,
258  std::function<Ptr<t_NetCalcData>(size_t )> clcdata_gttr,
259  std::function<void (size_t )> state_update,
260  std::function<bool (size_t )> synchronizer,
261  std::function<void (size_t, t_fexpcommon_ct )> dtmacro_sttr,
262  std::function<void (size_t, Ptr<CFEXGeomTools::t_BoundBox>, size_t )> mdmacro_sttr)
263  : ICFEXPNetNodeConnection(node_id, server_ip, port), _socket(socket), _client_ip(client_ip),
264  _thread_message_gttr(message_gttr),
265  _thread_message_lchr(message_lchr),
266  _thread_message_sttr(message_sttr),
267  _thread_clcdata_gttr(clcdata_gttr),
268  _thread_state_update(state_update),
269  _thread_synchronizer(synchronizer),
270  _thread_dtmacro_sttr(dtmacro_sttr),
271  _thread_mdmacro_sttr(mdmacro_sttr) { }
272 
273 protected:
274  TSocket _socket;
275  std::string _client_ip;
276 
277  // providers to server data
278  std::function<t_ENetThrdMsg (size_t, size_t )> _thread_message_gttr;
279  std::function<bool (size_t, size_t )> _thread_message_lchr;
280  std::function<void (size_t, size_t , t_ENetThrdMsg)> _thread_message_sttr;
281  std::function<Ptr<t_NetCalcData>(size_t )> _thread_clcdata_gttr;
282  std::function<void (size_t )> _thread_state_update;
283  std::function<bool (size_t )> _thread_synchronizer;
284  std::function<void (size_t, t_fexpcommon_ct )> _thread_dtmacro_sttr;
285  std::function<void (size_t, Ptr<CFEXGeomTools::t_BoundBox>, size_t )> _thread_mdmacro_sttr;
286 private:
287  // [no private members ] -----------------------------
288 };
289 
290 
296 /*template<typename TClient>
297 class ICFEXPNetServerConnectionProvider
298  : public ICFEXPNetNodeConnection
299 {
300 public:
301  ICFEXPNetServerConnectionProvider(size_t node_id, std::string server_ip, size_t port,
302  std::function<t_ENetThrdMsg (size_t, size_t )> message_gttr,
303  std::function<bool (size_t, size_t )> message_lchr,
304  std::function<void (size_t, size_t , t_ENetThrdMsg)> message_sttr,
305  std::function<Ptr<t_NetCalcData>(size_t )> clcdata_gttr,
306  std::function<void (size_t )> state_update,
307  std::function<bool (size_t )> synchronizer,
308  std::function<void (size_t, t_fexpcommon_ct )> dtmacro_sttr,
309  std::function<void (size_t, Ptr<CFEXGeomTools::t_BoundBox>, size_t )> mdmacro_sttr)
310  : ICFEXPNetNodeConnection(node_id, server_ip, port)
311  _thread_message_gttr(message_gttr),
312  _thread_message_lchr(message_lchr),
313  _thread_message_sttr(message_sttr),
314  _thread_clcdata_gttr(clcdata_gttr),
315  _thread_state_update(state_update),
316  _thread_synchronizer(synchronizer),
317  _thread_dtmacro_sttr(dtmacro_sttr),
318  _thread_mdmacro_sttr(mdmacro_sttr)
319  { }
320  virtual ~ICFEXPNetServerConnectionProvider() { }
321 
322  // pure virtual member functions
323  virtual Ptr<TClient> TryConnectNewClient (size_t id) = 0;
324  virtual bool GetIsClientDisconect() = 0;
325 protected:
326  // providers to server data
327  std::function<t_ENetThrdMsg (size_t, size_t )> _thread_message_gttr;
328  std::function<bool (size_t, size_t )> _thread_message_lchr;
329  std::function<void (size_t, size_t , t_ENetThrdMsg)> _thread_message_sttr;
330  std::function<Ptr<t_NetCalcData>(size_t )> _thread_clcdata_gttr;
331  std::function<void (size_t )> _thread_state_update;
332  std::function<bool (size_t )> _thread_synchronizer;
333  std::function<void (size_t, t_fexpcommon_ct )> _thread_dtmacro_sttr;
334  std::function<void (size_t, Ptr<CFEXGeomTools::t_BoundBox>, size_t )> _thread_mdmacro_sttr;
335 private:
336  // [no private members ] -----------------------------
337 };*/
338 
339 #endif // !_CFEXPNETWORKINTERFACE_H_
Definition: FEXPNetworkInterface.h:139
Definition: FEXPNetworkInterface.h:143
virtual ~ICFEXPNetBase()
Definition: FEXPNetworkInterface.h:29
std::function< void(size_t, t_fexpcommon_ct)> _thread_dtmacro_sttr
Definition: FEXPNetworkInterface.h:284
Definition: FEXPNetworkInterface.h:130
Definition: FEXPNetworkInterface.h:114
size_t GetCommPort()
Definition: FEXPNetworkInterface.h:57
Definition: FEXPNetworkInterface.h:160
virtual void Close()=0
Definition: FEXPNetworkInterface.h:99
Definition: FEXPNetworkInterface.h:116
std::atomic_bool _connection_start
Definition: FEXPNetworkInterface.h:64
std::function< bool(size_t, size_t)> _thread_message_lchr
Definition: FEXPNetworkInterface.h:279
Definition: FEXPNetworkInterface.h:162
Definition: FEXPNetworkInterface.h:157
std::vector< std::tuple< size_t, size_t > > MODEL_DATA_SET
Definition: FEXPNetworkInterface.h:228
virtual void SetId(size_t id) override
Definition: FEXPNetworkInterface.h:54
Definition: FEXPNetworkInterface.h:110
virtual Ptr< t_ModelData > GetMacroModelData()=0
Definition: FEXPNetworkInterface.h:124
Base network interface of a client node.
Definition: FEXPNetworkInterface.h:46
virtual ~ICFEXPNetNodeConnection()
Definition: FEXPNetworkInterface.h:51
virtual size_t GetId() const override
Definition: FEXPNetworkInterface.h:53
Definition: FEXPNetworkInterface.h:100
Definition: FEXPNetworkInterface.h:98
Definition: FEXPNetworkInterface.h:102
Definition: FEXPNetworkInterface.h:163
std::function< void(size_t, size_t, t_ENetThrdMsg)> _thread_message_sttr
Definition: FEXPNetworkInterface.h:280
t_ModelData RUNTIME_CLC_MACRO_DATA
Definition: FEXPNetworkInterface.h:231
Definition: FEXPNetworkInterface.h:107
TSocket _socket
Definition: FEXPNetworkInterface.h:274
Definition: FEXPNetworkInterface.h:103
CFEXPNetServerClientCalcData(Ptr< CFEXPSolverConfigSetting > setting)
Definition: FEXPNetworkInterface.h:213
std::string _client_ip
Definition: FEXPNetworkInterface.h:275
Definition: FEXPNetworkInterface.h:159
std::function< t_ENetThrdMsg(size_t, size_t)> _thread_message_gttr
Definition: FEXPNetworkInterface.h:278
Ptr< CFEXPSolverConfigSetting > _server_setting
Definition: FEXPNetworkInterface.h:235
Definition: FEXPCommon.h:276
double t_fexpcommon_ct
Definition: FEXPCommon.h:120
Definition: FEXPNetworkInterface.h:104
std::atomic_bool _data_received_prepared
Definition: FEXPNetworkInterface.h:217
Data for server clients.
Definition: FEXPNetworkInterface.h:210
ENETServerThreadMesage
Communication messages within the FEXP server.
Definition: FEXPNetworkInterface.h:155
virtual void Run()=0
Definition: FEXPNetworkInterface.h:140
Definition: FEXPNetworkInterface.h:161
static t_ModelData & GetReadModelData(Ptr< std::map< size_t, Ptr< t_ModelData >>> data, size_t key)
Definition: FEXPNetworkInterface.cpp:9
virtual size_t GetId() const =0
t_ModelData CURRENT_DATA_RECEIVED
Definition: FEXPNetworkInterface.h:221
ENETSynchronization
Synchronization nodes within the FEXP server.
Definition: FEXPNetworkInterface.h:137
std::vector< size_t > MODEL_DATA_GET
Definition: FEXPNetworkInterface.h:226
Definition: FEXPNetworkInterface.h:111
Definition: FEXPNetworkInterface.h:121
Definition: FEXPNetworkInterface.h:106
std::map< t_ModelDataKey, Ptr< t_ModelDataDta > > t_ModelData
Definition: FEXPDataContainer.h:15
Definition: FEXPNetworkInterface.h:109
std::function< void(size_t)> _thread_state_update
Definition: FEXPNetworkInterface.h:282
Definition: FEXPNetworkInterface.h:115
t_ModelData CURRENT_DATA_FOR_POUT
Definition: FEXPNetworkInterface.h:223
Definition: FEXPNetworkInterface.h:145
virtual void SendInstruction(size_t message, Ptr< t_ModelData > data)=0
Definition: FEXPNetworkInterface.h:90
Definition: FEXPNetworkInterface.h:141
EMainNETCommunicationPoint
Items of communication protocol.
Definition: FEXPNetworkInterface.h:95
std::function< TFunc()> get_thread_functor(std::function< TFunc(TInp)> thread_fce, std::function< TInp()> input)
Definition: FEXPNetworkInterface.h:78
std::atomic_bool _data_for_send_prepared
Definition: FEXPNetworkInterface.h:216
std::function< void(size_t, Ptr< CFEXGeomTools::t_BoundBox >, size_t)> _thread_mdmacro_sttr
Definition: FEXPNetworkInterface.h:285
ICFEXPNetServerClientNode(TSocket socket, std::string client_ip, size_t node_id, std::string server_ip, size_t port, std::function< t_ENetThrdMsg(size_t, size_t)> message_gttr, std::function< bool(size_t, size_t)> message_lchr, std::function< void(size_t, size_t, t_ENetThrdMsg)> message_sttr, std::function< Ptr< t_NetCalcData >(size_t)> clcdata_gttr, std::function< void(size_t)> state_update, std::function< bool(size_t)> synchronizer, std::function< void(size_t, t_fexpcommon_ct)> dtmacro_sttr, std::function< void(size_t, Ptr< CFEXGeomTools::t_BoundBox >, size_t)> mdmacro_sttr)
Definition: FEXPNetworkInterface.h:254
Definition: FEXPNetworkInterface.h:158
Definition: FEXPNetworkInterface.h:123
static t_MessageMap MESSAGES
Definition: FEXPNetworkInterface.h:168
Definition: FEXPNetworkInterface.h:127
Ptr< t_ModelDataDta > GetModelData(size_t key)
Definition: FEXPNetworkInterface.h:233
Definition: FEXPNetworkInterface.h:101
Definition: FEXPNetworkInterface.h:144
virtual void AddMacroModelData(const t_ModelDataKey &key, Ptr< t_ModelDataDta > data)=0
Definition: FEXPNetworkInterface.h:148
Definition: FEXPNetworkInterface.h:112
Definition: FEXPNetworkInterface.h:26
Definition: FEXPNetworkInterface.h:118
Definition: FEXPNetworkInterface.h:164
Network service on the client workstation side.
Definition: FEXPNetworkInterface.h:184
Base interface for server clients.
Definition: FEXPNetworkInterface.h:250
ICFEXPNetNodeConnection(size_t node_id, std::string server_ip, size_t port)
Definition: FEXPNetworkInterface.cpp:21
Definition: FEXPNetworkInterface.h:147
Definition: FEXPNetworkInterface.h:142
Definition: FEXPNetworkInterface.h:113
std::string t_ModelDataKey
Definition: FEXPDataContainer.h:13
Definition: FEXPNetworkInterface.h:105
Definition: FEXPNetworkInterface.h:120
virtual void SetId(size_t id)=0
Definition: FEXPNetworkInterface.h:146
t_ModelData INPUT_MACRO_MODEL_DATA
Definition: FEXPNetworkInterface.h:230
virtual Ptr< std::map< size_t, Ptr< t_ModelData > > > ReadInstruction()=0
std::map< EMainNETCommunicationPoint, std::string > t_MessageMap
Definition: FEXPNetworkInterface.h:167
static std::string GetNetMessage(EMainNETCommunicationPoint comm)
Definition: FEXPNetworkInterface.cpp:63
t_ModelData CURRENT_DATA_FOR_SEND
Definition: FEXPNetworkInterface.h:219
Definition: FEXPNetworkInterface.h:108
Definition: FEXPNetworkInterface.h:149
Definition: FEXPNetworkInterface.h:97
std::function< bool(size_t)> _thread_synchronizer
Definition: FEXPNetworkInterface.h:283
std::string GetServerNodeIP()
Definition: FEXPNetworkInterface.h:56
std::function< Ptr< t_NetCalcData >size_t)> _thread_clcdata_gttr
Definition: FEXPNetworkInterface.h:281
Definition: FEXPNetworkInterface.h:150